home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Frameworks / MacZoop 1.6.5 / More Classes / File Classes / ZFolderScanner.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-26  |  3.2 KB  |  133 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            ObjectMacZapp        -- a standard Mac OOP application template
  5. *
  6. *
  7. *
  8. *            ZFolderScanner.h    -- a generic object for recursively searching folders
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *            © 1996, Graham Cox
  15. *
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21.  
  22. #pragma once
  23.  
  24. #ifndef __ZFOLDERSCANNER__
  25. #define    __ZFOLDERSCANNER__
  26.  
  27. #ifndef __ZFILE__
  28. #include    "ZFile.h"
  29. #endif
  30.  
  31. class    ZProgress;
  32.  
  33.  
  34. class    ZFolderScanner : public ZFile
  35. {
  36. protected:
  37.     short        curDepth;    
  38.     short        searchDepth;
  39.     long        topDirID;
  40.     Boolean        useProgressDialog;
  41.     ZProgress*    itsPD;
  42.     CInfoPBRec     pb;
  43.     Str31        fName;
  44.  
  45. public:    
  46.     ZFolderScanner( const FSSpec& rootFolder );
  47.     ZFolderScanner();
  48.     
  49.     ~ZFolderScanner();
  50.     
  51.     virtual void    SetSearchDepth( const short aSearchDepth );
  52.     virtual Boolean    PickFolder();
  53.     
  54.     virtual void    ScanFolder();
  55.     
  56. protected:
  57.     virtual void    Scan1Folder( const long dirID );
  58.     virtual void    Process1File( const FSSpec& aSpec, const OSType fType );
  59.     virtual void    Process1Folder( const FSSpec& aSpec );
  60. };
  61.  
  62.  
  63.  
  64. typedef struct
  65. {
  66.     StandardFileReply    aReply;
  67.     Boolean                selectHit;
  68.     Boolean                dirFlag;
  69. }
  70. tFolderInfo;
  71.  
  72.  
  73.  
  74. pascal    OSErr    GetDirectoryID(short vRefNum,
  75.                                long dirID,
  76.                                StringPtr name,
  77.                                long *theDirID,
  78.                                Boolean *isDirectory);
  79.                        
  80. pascal    OSErr    FSpGetDirectoryID(const FSSpec *spec,
  81.                                   long *theDirID,
  82.                                   Boolean *isDirectory);
  83.                                   
  84. Boolean                    ChooseFolder(FSSpec* folderSpec);
  85. Boolean                    GetFullPathname(FSSpec* aSpec, Str255 pathname);
  86. OSErr                     MakeCanonFSSpec ( FSSpec *spec );
  87. Boolean                 SameFile ( FSSpec *spec1, FSSpec *spec2 );
  88.  
  89.  
  90. static pascal Boolean    GetDirFileFilter(ParmBlkPtr pb, tFolderInfo* fInfo);
  91. static pascal short        GetDirDlgHook(short item, DialogPtr theDialog, tFolderInfo* fInfo);
  92. static void                SetSFButtonTitle(ControlHandle theButton, FSSpec* theFile, Rect* buttonRect);
  93. static short            GetSFCurVol();
  94. static long                GetSFCurDir();
  95. static void                pStrInsert(StringPtr dest, StringPtr src);
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.                      
  104.  
  105. /*
  106.  
  107. This object is useful for doing general recursive searches through a hierarchy of folders. For
  108. each file it encounters, it calls Process1File with the file spec. You can override this
  109. method to do whatever you want with the file. If another folder is encountered, it calls
  110. Scan1Folder recursively to the maximum depth you set with SetSearchDepth(). By default this is
  111. 0, so it only searches the first folder. Pass -1 to search all folders below the first folder
  112. as well. If you want to search the entire hard disk, pass the FSSpec of the hard disk in the
  113. constructor, or use the default constructor to search the startup disk.
  114.  
  115. To kick off a search, simply call ScanFolder().
  116.  
  117. To provide a user-interface for selecting a folder, call PickFolder(). This presents a custom
  118. Standard File dialog to pick a folder, which then becomes the current folder. You can then call
  119. ScanFolder to search it.
  120.  
  121. Sincethis inherits from ZFile, you can call GetFSSpec, etc. However, it is meaningless to try to
  122. call Open, etc. on this object, since the spec should be for a folder.
  123.  
  124. */
  125.  
  126.  
  127.  
  128. #define        kDefaultSearchDepth            0
  129. #define        kPickFolderDialogID            8001
  130. #define        kPickFolderButton            13
  131. #define        kStdButtonTextStrID            128
  132.  
  133. #endif